<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>

    <meta charset="UTF-8">
    <title>物资入库</title>
    <script th:src="@{/js/jquery.min.js}"></script>
    <style>
        .greenStyle {
            background: lightgreen;
        }
    </style>
    <script>
        $(document).ready(function () {
        document.getElementById("stockInId").focus()
        });

        function entertext() {
            document.getElementById("fbarcode").focus()
        }
        function queryMsg() {
            var fbarcode = document.getElementById("fbarcode").value;
            var stockInId = document.getElementById("stockInId").value;
            if (fbarcode == "" || fbarcode == null) {
                alert("物资条码不能为空！");
                $('#fbarcode').val("");
                document.getElementById("fbarcode").focus()
                return;
            }if (stockInId == "" || stockInId == null) {
                alert("交货单不能为空！");
                $('#fbarcode').val("");
                document.getElementById("fbarcode").focus()
                return;
            }

            $.post("/pdaPk1/tms/listSH", {
                fbarcode: fbarcode,
                stockInId:stockInId
            }, function (result) {
                if (result == null) {
                    alert("单据不存在");
                    $('#fbarcode').val("");
                    document.getElementById("fbarcode").focus()
                    return
                }
                // if (result["status"] != null && result["status"] > 0) {
                //     alert("此物资已提交信息,不能重复收货")
                //     return
                // }
                var rows = document.getElementById("detailMsg1").rows.length;
                if (rows > 1) {
                    var tab2 = document.getElementById("detailMsg1");
                    for (var j = rows; j > 1; j--) {
                        tab2.deleteRow(j - 1);
                    }
                }

                var productId = result["nowMatnr"]
                var data = result["matnrList"]
                $('#matnr').val(productId)
                var quantity = result["qty"];
                var quantity1 = result["qtyout"];
                $('#quantity').val(quantity);
                $('#quantityout').val(quantity1);
                $('#fbarcode').val("");
                // document.getElementById("fbarcode").focus()
                if (data != null) {
                    var str = "";
                    for (var i = 0; i < data.length; i++) {
                            str = "<tr><td>" + data[i].matnr + " </td><td>" + data[i].maktx + " </td><td>"
                                // + data[i].fbarcode + " </td><td>"
                                + data[i].fnum + " </td><td>" + data[i].fpackunit +" </td><tr>";
                            $("#detailMsg1").append(str);
                    }
                }
                document.getElementById("fbarcode").focus()
                alert(result["isnull"]);
            }, "json");
        }

        function SureSH() {
            var fbarcode = document.getElementById("fbarcode").value;
            var stockInId = document.getElementById("stockInId").value;
            var productId ="";
            if (stockInId == "" || stockInId == null) {
                alert("交货单不能为空！");
                return;
            }

            $.post("/pda/SureSH1", {
                fbarcode: fbarcode,
                inStockId:stockInId,
                productId:productId
            }, function (result) {
                alert(result.status)
                // if ( result.status == 0) {
                //     alert("此物资已收货,不能重复收货")
                //     document.getElementById("fbarcode").value ="";
                //     // var selectRow = document.getElementById("detailMsg1").rows[0];
                //     var rows = document.getElementById("detailMsg1").rows.length - 1;
                //     for (var i = 0; i < rows; i++) {
                //          document.getElementById("detailMsg1").rows[i + 1] = "";
                //     }
                //     return
                // }else{
                //     alert("此物资已收货,不能重复收货")
                //     document.getElementById("fbarcode").value ="";
                //     return
                // }

            }, "json");

        }

    </script>
</head>
<body>
<table id="tbb" width="98%" border="1" align="center" cellPadding="0" cellSpacing="0">
    <tr>
        <td align="center">交货单号:</td>
        <td><input id="stockInId" type="text" name="stockInId" style="width: 95%" oninput="entertext()"/>
        </td>
    </tr>
    <tr>
        <td align="center">子件条码:</td>
        <td><input id="fbarcode" type="text" name="fbarcode" style="width: 95%" oninput="queryMsg()" />
<!--            <button id="btn" type="button" onclick="queryMsg()" style="width: 20%">查询</button>-->
        </td>
    </tr>
<!--    <tr>-->
<!--        <td align="right">物资编码：</td>-->

<!--        <td><input id="matnr" type="text" name="matnr" style="width: 100%" readonly></td>-->
<!--    </tr>-->
    <tr>
        <td align="left">
            数量：
        <input type="text" id="quantity" name="quantity" style="width: 55%" readonly></td>
        <td align="left">
            已扫描数量：
        <input type="text" id="quantityout" name="quantityout" style="width: 40%" readonly></td>
    </tr>
    <tr>
        <td align="center" colspan="2">
            <table id="detailMsg1" name="detailMsg1" border="1px">
                <tbody>
                <tr>
<!--                    <td>交货单号 </td>-->
                    <td>子物资编码 </td>
                    <td>物资名称 </td>
<!--                    <td>子件条码 </td>-->
                    <td>数量 </td>
                    <td>单位 </td>

                </tr>
                </tbody>
            </table>
        </td>
    </tr>



    <tr>
        <td height="25" bgcolor="#d9e8fc" align="center" colSpan="2">
            <table width="100%">
                <tr>
                    <td width="60%" align="center">
                        <button id="btn_submit2" type="button" onclick="SureSH()" style="width:30%;"> 确认收货</button>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
</body>
</html>